package view;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

import options.view.ViewSettings;

public class SplashScreen extends JWindow  {
	
	private static final long serialVersionUID = 5702237859152988919L;
	private static SplashScreen splash = null;
	private JPanel jContentPane = null;
	private JLabel lblBackground = null;
	private static FrameWork frame = null;

	/**
	 * This is the default constructor
	 */
	private SplashScreen(FrameWork owner) {
		super(owner);
		frame = owner;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(550, 300);
        this.setContentPane(getJContentPane());
		this.setAlwaysOnTop(true);
		ViewSettings.getSettings().centerDialog(this);
		this.setVisible(true);
		this.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				SplashScreen.this.dispose();
				SplashScreen.frame.getStatusLabel().setText("Monitor SNMP avviato.");
			}
		});
	}

	/**
	 */
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {			
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			
			try {
				lblBackground = new JLabel(new ImageIcon("images/sfondo.png"));	            
			} catch (Exception ex) {
				lblBackground = new JLabel("Unable to load the image");
			}
			lblBackground.setBounds(new java.awt.Rectangle(0,0,550,300));
			jContentPane.add(lblBackground, null);
			
		}
		return jContentPane;
	}
	
	public static SplashScreen NewSplashScreen(FrameWork owner) {
		if(splash == null) {
			splash = new SplashScreen(owner);
			
			new Thread(new Runnable() {
				public void run() {
			        try {
						Thread.sleep(2000);
						splash.dispose();
						frame.getStatusLabel().setText("Monitor SNMP avviato.");
						Thread.sleep(8000);
						frame.getStatusLabel().setText(" ");
					} catch (InterruptedException exc) {}
				}
			}).start();
		}
		return splash;
	}
}
